<!-- 添加设备 -->
<template>
	<view>
		<view>
			<navitop>
				<i class="iconfont" slot="left-slot" @click="outlot">&#xe667;</i>
				<span slot="center-slot">修改设备配置</span>
				<!-- <i class="iconfont icon-youcecaidan" slot="right-slot" @click="Bubble(data)"></i> -->
			</navitop>
		</view>
		<view :style="'padding-top:' + nv_height + ';'" >
			<div class="public_input_list">
				<div class="public_other_input_list">
					<div class="public_other_input_left"><span>*</span>广播地址：</div>
					<div class="public_other_input_right subpage_input">
						<input v-model="edit_data.address" />
					</div>
				</div>
				<div class="public_other_input_list">
					<div class="public_other_input_left"><span>*</span>品牌名称：</div>
					<div class="public_other_input_right subpage_input">
						<input v-model="edit_data.name" />
					</div>
				</div>
				<div class="public_other_input_list">
					<div class="public_other_input_left">规格型号：</div>
					<div class="public_other_input_right subpage_input">
						<input v-model="edit_data.specification" />
					</div>
				</div>
				<div class="public_other_input_list">
					<div class="public_other_input_left">使用状态：</div>
					<view class="out_switch" v-if="edit_data.status == 1">
						<switch name="switch" @click="status_form(0)"  checked />
					</view>
					<view class="out_switch" v-else>
						<switch name="switch" @click="status_form(1)"   />
					</view>
				</div>
			</div>
			<div class="public_other_bottom" @click="PAD_save">
				<div>保存</div>
			</div>
		</view>
	</view>
</template>

<script>
import navitop from '@/components/common/navi-top'
import {pdasave,pdapageList} from '@/common/api/my/subpage.js'
export default {
	components: {
		navitop
	},
	data(){
		return {
			nv_height: '',
			http_data: '',
			edit_data: [],	// 获取修改数据
		}
	},
	onLoad(option) {
		this.http_data = option;
	},
	mounted() {
		this.nv_height = uni.getSystemInfoSync().statusBarHeight + 65 + 'px';
		
		this.PDA_list();
	},
	methods: {
		
		PDA_list(){
			let _this = this;
			pdapageList().then(item => {
				if(item.code == 200){
					item.data.records.forEach(item => {
						if(item.id == this.http_data.id){
							_this.edit_data = item;
						}
					})
					
				}
			})
		},
		
		status_form(val){
			this.edit_data.status = val
		},
		
		// 返回
		outlot(){
			uni.redirectTo({
				url: '/pages/my/subpage/equipment_list'
			})
		},
		
		// 保存
		PAD_save(){
			if(!this.edit_data.address){
				uni.showToast({
					title: '请输入广播地址!',
					icon: 'none'
				})
				return false;
			}
			if(!this.edit_data.name){
				uni.showToast({
					title: '请输入品牌名称!',
					icon: 'none'
				})
				return false;
			}
			uni.showLoading({
				title: '加载中。。。'
			})
			pdasave(this.edit_data).then(item => {
				if(item.code == 200){
					console.log(item)
					uni.hideLoading();
					uni.showToast({
						title: '修改成功！',
						icon: 'none'
					})
					setTimeout(()=> {
						uni.redirectTo({
							url: '/pages/my/subpage/equipment_list'
						})
					},1500)
				}else{
					uni.showToast({
						title: '网络异常！',
						icon: 'none'
					})
				}
			})
		},
	
	}
}
</script>

<style scoped lang="scss">
 @import '@/static/css/common/public_css.scss';
.subpage_input {
	input {
		border: 0;
		border-bottom: 1px solid #cacaca;
	}
}
.subape_out {
	border: 1px solid red;
	
}
</style>
